package com.ruoyi.project.platform.mapper;

import java.util.List;
import com.ruoyi.project.platform.domain.RRunningMapping;
import com.ruoyi.project.platform.dto.RRunningMappingDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 运行机器人参数Mapper接口
 * 
 * @author ruoyi
 * @date 2020-07-26
 */
@Mapper
public interface RRunningMappingMapper 
{
    /**
     * 查询运行机器人参数
     * 
     * @param runningId 运行机器人参数ID
     * @return 运行机器人参数
     */
    public RRunningMapping selectRRunningMappingById(Long runningId);

    /**
     * 查询运行机器人参数列表
     * 
     * @param rRunningMapping 运行机器人参数
     * @return 运行机器人参数集合
     */
    public List<RRunningMapping> selectRRunningMappingList(RRunningMapping rRunningMapping);

    /**
     * 查询运行机器人参数列表
     *
     * @param rRunningMapping 运行机器人参数
     * @return 运行机器人参数集合
     */
    @Select("SELECT " +
            " t.*, " +
            " r.running_id AS runningId, " +
            " r.parameter_value AS parameterValue  " +
            "FROM " +
            " ( " +
            "SELECT " +
            " p.`name`, " +
            " p.description, " +
            " p.default_value AS defaultValue, " +
            " p.parameter_id AS parameterId  " +
            "FROM " +
            " sty_strategy s " +
            " JOIN sty_parameter p ON s.strategy_id = p.strategy_id  " +
            " JOIN r_robot_running robot ON (s.strategy_id = robot.strategy_id and robot.running_id=#{map.runningId}) "+
            " ) t " +
            " LEFT JOIN ( SELECT * FROM r_running_mapping WHERE running_id = #{map.runningId} ) r ON t.parameterId = r.parameter_id")
    public List<RRunningMappingDto> selectRRunningMappingDtoList(@Param("map") RRunningMapping rRunningMapping);

    /**
     * 新增运行机器人参数
     * 
     * @param rRunningMapping 运行机器人参数
     * @return 结果
     */
    public int insertRRunningMapping(RRunningMapping rRunningMapping);

    /**
     * 修改运行机器人参数
     * 
     * @param rRunningMapping 运行机器人参数
     * @return 结果
     */
    public int updateRRunningMapping(RRunningMapping rRunningMapping);

    /**
     * 删除运行机器人参数
     * 
     * @param runningId 运行机器人参数ID
     * @return 结果
     */
    public int deleteRRunningMappingById(Long runningId);

    /**
     * 批量删除运行机器人参数
     * 
     * @param runningIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteRRunningMappingByIds(Long[] runningIds);

    @Delete("DELETE  " +
            "FROM " +
            " `r_running_mapping`  " +
            "WHERE " +
            " parameter_id = #{parameterId}  " +
            " AND running_id = #{runningId}")
    public int deleteRRunningMappingByUniId(@Param("runningId") Long runningId, @Param("parameterId") Long parameterId);
}
